package com.awakensoftware.hunterserver.web.rest;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import com.awakensoftware.communicationprotocol.contractobjects.errors.ErrorContractObject;
import com.awakensoftware.communicationprotocol.contractobjects.treasures.TreasureContractObject;
import com.awakensoftware.hunterserver.serverentities.Chest;
import com.awakensoftware.hunterserver.serverentities.Treasure;
import com.awakensoftware.hunterserver.services.TreasureService;

@RestController
@RequestMapping("/rest/treasures/**")
public class TreasureAPIController extends RestEntityControllerBase<Treasure, TreasureContractObject> {

	@Autowired
	private TreasureService treasureService;

	@RequestMapping(value = "/instance/{id}", method = RequestMethod.GET, produces = "application/json")
	public TreasureContractObject getTreasureById(@PathVariable("id") long id) {
		Treasure treasure = treasureService.create();
		treasure.setChest(new Chest());
		return super.getRestResponseFromServerEntity(treasure);
	}

	@Override
	@ExceptionHandler(Exception.class)
	@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
	public ErrorContractObject handleException(Exception ex, HttpServletRequest request) {
		return super.getErrorContractObject(ex);
	}

}
